package com.wmyg.antifake.gs1.ns2.converters;

import com.wmyg.antifake.gs1.ns2.SpecialString;
import com.wmyg.antifake.gs1.ns2.TSDProductOriginInformationModule;
import com.wmyg.antifake.gs1.ns2.origin.CountryOfOrigin;
import org.dom4j.Element;

import java.util.List;

/**
 * @program: antifake
 * @description: 商品源头信息转换器
 * @author: wong
 * @create: 19-4-23
 */
public class ProductOriginInformationConverter {

    protected static TSDProductOriginInformationModule convert(Element element) {
        TSDProductOriginInformationModule p = new TSDProductOriginInformationModule();
        List<Element> children = element.elements();
        for (Element e :
                children) {
            if ("countryOfOrigin".equals(e.getName())) {
                CountryOfOrigin countryOfOrigin = new CountryOfOrigin();
                Element countryCode = e.element("countryCode");
                countryOfOrigin.setCountryCode(new SpecialString(countryCode));
                p.setCountryOfOrigin(countryOfOrigin);
            } else {
                p.setMap(MapConverter.elementToMap(e));
            }
        }
        return p;
    }

}
